﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ZLDC.Common.Estate;

namespace ZLDC.Estate
{
    public class CacheUtility
    {
        #region 片区授权

        public static string Cache_GetAreaAndUseByDeptId(int deptid)
        {
            string condition = "";
            string cachekey = "GetAreaByDeptId_AndUse_" + deptid.ToString();

            if (_Cache.GetCache(cachekey) == null || _Cache.GetCache(cachekey).ToString() == "")
            {
                condition = ZLDC.Topo.BLL.Estate.HousingBLL.GetAreaAndUseByDeptId(deptid);
                if (condition != "")
                    _Cache.SetCache(cachekey, condition, 3600 * 1);
            }
            else
                condition = _Cache.GetCache(cachekey).ToString();

            return condition;
        }

        public static string Cache_GetAreaByDeptId(int deptid)
        {
            string condition = "";
            string cachekey = "GetAreaByDeptId_" + deptid.ToString();

            if (_Cache.GetCache(cachekey) == null || _Cache.GetCache(cachekey).ToString() == "")
            {
                condition = ZLDC.Topo.BLL.Estate.HousingBLL.GetAreaByDeptId(deptid);
                if (condition != "")
                    _Cache.SetCache(cachekey, condition, 3600 * 1);
            }
            else
                condition = _Cache.GetCache(cachekey).ToString();

            return condition;
        }

        public static string Cache_GetNoAreaByDeptId(int deptid)
        {
            string condition = "";
            string cachekey = "GetNoAreaByDeptId_" + deptid.ToString();

            if (_Cache.GetCache(cachekey) == null || _Cache.GetCache(cachekey).ToString() == "")
            {
                condition = ZLDC.Topo.BLL.Estate.HousingBLL.GetNoAreaByDeptId(deptid);
                if (condition != "")
                    _Cache.SetCache(cachekey, condition, 3600 * 1);
            }
            else
                condition = _Cache.GetCache(cachekey).ToString();

            return condition;
        }

        public static string Cache_GetAreaByDeptId2(int deptid)
        {
            string condition = "";
            string cachekey = "GetAreaByDeptId_2_" + deptid.ToString();

            if (_Cache.GetCache(cachekey) == null || _Cache.GetCache(cachekey).ToString() == "")
            {
                condition = ZLDC.Topo.BLL.Estate.HousingBLL.GetAreaByDeptId2(deptid);
                if (condition != "")
                    _Cache.SetCache(cachekey, condition, 3600 * 1);
            }
            else
                condition = _Cache.GetCache(cachekey).ToString();

            return condition;
        }

        #endregion

        #region 上级|下级部门

        public static string Cache_GetAllChildDept(string deptid)
        {
            string condition = "";
            string cachekey = "GetAllChildDept_" + deptid.ToString();

            if (_Cache.GetCache(cachekey) == null || _Cache.GetCache(cachekey).ToString() == "")
            {
                condition = ZLDC.Common.BaseUser.UserInfo.getAllChildDept(deptid, "0");
                if (condition != "")
                    _Cache.SetCache(cachekey, condition, 3600 * 1);
            }
            else
                condition = _Cache.GetCache(cachekey).ToString();

            return condition;
        }

        #endregion

        #region 楼盘栋阁

        public static string Cache_BuildIdListByEname_Json(string estatename)
        {
            string json = "";

            string useage = "";
            string cachekey = "BuildIdListByEname_" + estatename;

            if (HttpContext.Current.Session["useage"] != null || HttpContext.Current.Session["useage"] != "")
            {
                useage = HttpContext.Current.Session["useage"].ToString();
                cachekey += "_" + useage;
            }



            if (_Cache.GetCache(cachekey) == null || _Cache.GetCache(cachekey).ToString() == "")
            {
                json = ZLDC.Topo.BLL.Estate.BuildBLL.BuildIdListByEname(estatename);
                if (json != "")
                    _Cache.SetCache(cachekey, json, 3600 * 12);
            }
            else
                json = _Cache.GetCache(cachekey).ToString();

            return json;
        }



        public static string Cache_BuildIdListByEname_Json(string estatename, string buildname)
        {
            string json = "";
            string useage = "";
            string cachekey = "BuildIdListByEname_" + estatename + "_" + buildname;

            if (HttpContext.Current.Session["useage"] != null || HttpContext.Current.Session["useage"] != "")
            {
                useage = HttpContext.Current.Session["useage"].ToString(); cachekey += "_" + useage;
            }

            if (_Cache.GetCache(cachekey) == null || _Cache.GetCache(cachekey).ToString() == "")
            {
                json = ZLDC.Topo.BLL.Estate.BuildBLL.BuildIdListByEname(estatename, buildname);
                if (json != "")
                    _Cache.SetCache(cachekey, json, 3600 * 12);
            }
            else
                json = _Cache.GetCache(cachekey).ToString();

            return json;
        }

        public static string Cache_BuildIdListByEnameAndBname_Json(string estatename)
        {
            string json = "";
            string cachekey = "BuildIdListByEnameAndBname_" + estatename;

            if (_Cache.GetCache(cachekey) == null || _Cache.GetCache(cachekey).ToString() == "")
            {
                json = ZLDC.Topo.BLL.Estate.BuildBLL.BuildIdListByEnameAndBname(estatename);
                if (json != "")
                    _Cache.SetCache(cachekey, json, 3600 * 12);
            }
            else
                json = _Cache.GetCache(cachekey).ToString();

            return json;
        }

        #endregion
    }

}
